package com.xhj.ipersistent.session;

import com.xhj.ipersistent.config.Configuration;
import com.xhj.ipersistent.executor.SimpleExecutor;

/**
 * DefaultSqlSessionFactory
 *
 * @author XJks
 * @description SqlSessionFactory接口的默认实现类
 */
public class DefaultSqlSessionFactory implements SqlSessionFactory {
    /**
     * 全局配置对象
     */
    private final Configuration configuration;

    public DefaultSqlSessionFactory(Configuration configuration) {
        this.configuration = configuration;
    }

    @Override
    public SqlSession openSession() {
        // 创建执行器对象
        SimpleExecutor simpleExecutor = new SimpleExecutor(configuration);
        // 创建sqlSession对象
        DefaultSqlSession defaultSqlSession = new DefaultSqlSession(configuration, simpleExecutor);
        return defaultSqlSession;
    }
}
